package com.congee02.modelshellmvn.advice;

import com.congee02.modelshellmvn.entity.account.Account;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class UniformMessage {

    private boolean success;

    private String message;

    private Object data;

    private int code;

    public static UniformMessage fail(String message, Object data) {
        return new UniformMessage().setSuccess(false).setMessage(message).setData(data).setCode(500);
    }

    public static UniformMessage fail(String message) {
        return fail(message, null);
    }

    public static UniformMessage fail() {
        return fail(null);
    }

    public static UniformMessage ok(String message, Object data) {
        return new UniformMessage().setSuccess(true).setMessage(message).setData(data).setCode(20000);
    }

    public static UniformMessage ok(String message) {
        return ok(message, null);
    }

    public static UniformMessage ok() {
        return ok(null);
    }

    public static UniformMessage ok(Object data) {
        return ok(null, data);
    }

    public UniformMessage setData(Object data) {
        this.data = data;
        if (data instanceof Account) {
            ((Account) data).setPassword(null);
        }
        return this;
    }
}
